import { _decorator, Component, UIOpacity, CCInteger} from 'cc';

const { ccclass, property } = _decorator;

// 一闪一闪
@ccclass('WheelFlashView')
export class WheelFlashView extends Component {
    @property({
        type: CCInteger,
        tooltip: "说明"
    })
    w: number

    // start() {
    //
    // }

    elapsed: number
    onLoad() {
        this.elapsed = 0
        this.w = this.w || 4 // 设置默认值为4
        const opacity = this.node.getComponent(UIOpacity)
        if (!opacity) {
            // 添加透明度组件
            this.node.addComponent(UIOpacity)
        }
    }
    update(dt) {
        const opacity = this.node.getComponent(UIOpacity)
        const elapsed = this.elapsed += dt
        opacity.opacity = ((Math.sin(this.w * elapsed) + 1) / 2) * 255
    }
    
    onDisable() {
        const opacity = this.node.getComponent(UIOpacity)
        opacity.opacity = 255
    }
}
